package Constructions;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URLClassLoader;

import javax.imageio.ImageIO;

import Main.SpaceGame;

public class Recycler extends Construction
{
	private BufferedImage sprite1 = null, sprite2 = null;
	int animateCnt;
	int currentAnimation;
	
	public Recycler(int x, int y, SpaceGame main) 
	{
		super(x, y, main);
		width = 2;
		height = 2;
		workingTile = main.world.tiles[x][y+1];
		animateCnt = 15;
		currentAnimation = 1;
		try {
			sprite1 = ImageIO.read(URLClassLoader.getSystemResource("Resources/"+"Recycler1.png"));
			sprite2 = ImageIO.read(URLClassLoader.getSystemResource("Resources/"+"Recycler2.png"));
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void draw(Graphics g) 
	{
		if(animateCnt > 0 && !main.paused() && powered)
		{
			animateCnt--;
		}
		else
		{
			animateCnt = 15;
			if(currentAnimation == 1)
				currentAnimation = 2;
			else
				currentAnimation = 1;
		}
		if(currentAnimation == 1)
			g.drawImage(sprite1,x*10,y*10,null);
		else
			g.drawImage(sprite2,x*10,y*10,null);
		drawFlash(g, x, y);
	}

	@Override
	public void setText() 
	{
		textColorIndex = 1;
		
		colors.add(Color.cyan);
		text.add(getName());
		
		if(powered)
		{
			colors.add(Color.cyan);
			text.add("");
			
			colors.add(Color.green);
			text.add("Powered");
		}
		else
		{
			colors.add(Color.cyan);
			text.add("");
			
			colors.add(Color.red);
			text.add("Needs Power");
		}
	}

	@Override
	public String getName() 
	{
		return "Recyler";
	}
	
	@Override
	public void keyTyped(KeyEvent e) 
	{
		
	}

	@Override
	public void keyPressed(KeyEvent e) 
	{
		
	}

	@Override
	public void keyReleased(KeyEvent e) 
	{
		
	}
}
